package ua.races.command.implementation;

import ua.races.command.ServletCommand;
import org.apache.log4j.Logger;
import ua.races.dao.RacesDaoImpl;
import ua.races.vo.BetType;
import ua.races.vo.Race;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class AddNewBetCommand implements ServletCommand {
    private static final Logger log = Logger.getLogger(AddNewBetCommand.class.getName());

    public void execute(HttpServletRequest req, HttpServletResponse resp, ServletContext context) {

        RacesDaoImpl dao;
        dao = (RacesDaoImpl) context.getAttribute("DAO");
        String raceId = null;
        List<BetType> betTypes =  null;

        try {
            raceId = req.getParameter("raceId");
            betTypes = dao.findAllBetTypes();
        } catch (SQLException e) {
            log.error(e);
        }

        req.setAttribute("raceId",raceId);
        req.setAttribute("betTypes",betTypes);

        try {
            context.getRequestDispatcher("/typeOfBetChoose.jsp").forward(req, resp);
        } catch (ServletException e) {
            log.error(e);
        } catch (IOException e) {
            log.error(e);
        }

    }
}
